home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer: Getting Started / Internet Surfer - Getting Started (Wayzata Technology)(7231)(1995).bin / pc / mac / bonus / peter_le / finger-1 / my_units / myteutil.s < prev    next >
Text File  |  1992-02-24  |  2KB  |  80 lines

  1. unit MyTEUtils;
  2.  
  3. { This code is part of the Finger/Fingerd source code, written in THINK Pascal 4 }
  4. { Copyright 1991-1992 Peter N Lewis }
  5. { If you use this code, you must give me credit in your about box and documentation }
  6. { This is part of my generic library of routines }
  7.  
  8. interface
  9.  
  10.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longInt): boolean;
  11.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longInt; item: integer);
  12.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longInt; item: integer): boolean;
  13.  
  14. implementation
  15.  
  16.     uses
  17.         MyTypes, BaseGlobals, MyUtils;
  18.  
  19.     function TEEditMenuEnabled (te: TEHandle; static: boolean; maxsize: longInt): boolean;
  20.         var
  21.             i: integer;
  22.     begin
  23.         for i := EMundo to EMselectall do
  24.             TESetEditMenuItem(te, static, maxsize, i);
  25.         TEEditMenuEnabled := GetMHandle(M_Edit)^^.enableFlags <> 0;
  26.     end;
  27.  
  28.     procedure TESetEditMenuItem (te: TEHandle; static: boolean; maxsize: longInt; item: integer);
  29.         var
  30.             offset: longInt;
  31.     begin
  32.         case item of
  33.             EMundo: 
  34.                 SetIDItemEnable(M_Edit, item, false);
  35.             EMcut, EMclear: 
  36.                 SetIDItemEnable(M_Edit, item, not static & (te^^.selStart < te^^.selEnd));  { Can cut,clear if there is a selection }
  37.             EMcopy: 
  38.                 SetIDItemEnable(M_Edit, item, te^^.selStart < te^^.selEnd);  { Can copy iff there is a selection }
  39.             EMpaste: 
  40.                 SetIDItemEnable(M_Edit, item, not static & (GetScrap(nil, 'TEXT', offset) > 0) & (TEGetScrapLen + (te^^.teLength - (te^^.selEnd - te^^.selStart)) < maxsize));
  41.             EMselectall: 
  42.                 SetIDItemEnable(M_Edit, item, te^^.teLength > 0);  { Can select all iff there is something to select }
  43.             otherwise
  44.         end;
  45.     end;
  46.  
  47.     function TEDoEditMenu (te: TEHandle; static: boolean; maxsize: longInt; item: integer): boolean;
  48.         var
  49.             loe, oe: OSErr;
  50.     begin
  51.         TEDoEditMenu := true;
  52.         case item of
  53.             EMcopy:  begin
  54.                 TECopy(te);
  55.                 loe := ZeroScrap;
  56.                 oe := TEToScrap;
  57.                 TEDoEditMenu := false;
  58.             end;
  59.             EMselectall:  begin
  60.                 SetPort(FrontWindow);
  61.                 TESetSelect(0, maxLongInt, te);
  62.                 TEDoEditMenu := false;
  63.             end;
  64.             EMcut:  begin
  65.                 TECut(te);
  66.                 loe := ZeroScrap;
  67.                 oe := TEToScrap;
  68.             end;
  69.             EMclear:  begin
  70.                 TEDelete(te);
  71.             end;
  72.             EMpaste:  begin
  73.                 oe := TEFromScrap;
  74.                 TEPaste(te);
  75.             end;
  76.             otherwise
  77.         end;
  78.     end;
  79.  
  80. end.